/**
 * 基础菜单 user管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>普通员工管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="查询员工信息">
        <el-input size="small" v-model="inputEmpId" placeholder="输入员工编号" @keyup.enter.native="getEmployeesByEmpId"></el-input>
      </el-form-item>
      <el-form-item label="员工上班打卡">
        <el-input size="small" v-model="clockInEmpId" placeholder="输入员工编号" @keyup.enter.native="clockIn"></el-input>
      </el-form-item>
      <el-form-item label="员工下班打卡">
        <el-input size="small" v-model="clockOutEmpId" placeholder="输入员工编号" @keyup.enter.native="clockOut"></el-input>
      </el-form-item>
      <!-- <el-form-item label="查询打卡信息">
        <el-input size="small" v-model="selectRecord" placeholder="输入员工编号" @keyup.enter.native="getRecordByEmpId"></el-input>
      </el-form-item> -->
      </el-form>
    <!-- 显示查询得到员工数据 -->
    <el-table :data="tableData" height="250"
    border
    style="width: 100%">
    <el-table-column prop="emp_id" label="emp_id" width="180">
    </el-table-column>
    <el-table-column prop="name" label="name" width="180">
    </el-table-column>
    <el-table-column prop="department_id" label="department_id" width="180">
    </el-table-column>
    <el-table-column prop="job_id" label="job_id" width="180">
    </el-table-column>
    <el-table-column prop="basic_Salary" label="basic_Salary" width="180">
    </el-table-column>
    <el-table-column prop="arrival_time" label="arrival_time" width="180">
    </el-table-column>
    <el-table-column prop="departure_time" label="departure_time" width="180">
    </el-table-column>
    <el-table-column prop="rest_holiday" label="rest_holiday" width="180">
    </el-table-column>
    <el-table-column prop="monthly_salary" label="monthly_salary" width="180">
    </el-table-column>
   
    </el-table>
    
<!-- 记录查询员工打卡表 -->
<el-button type="primary" @click="dialogVisible = true">查询请假记录</el-button>
  <el-dialog :visible.sync="dialogVisible">
            <p>empId:{{selectRecord}}</p>
  <el-form @submit.native.prevent>
              <el-input v-model="selectRecord"
                placeholder="输入员工编号"
                @keyup.enter.native="getstatus">
              </el-input>
  </el-form>
    <el-table :data="recordTableData" height="250"
        border
        style="width: 100%">
        <el-table-column prop="status" label="status" width="180">
        </el-table-column>
    </el-table>
  </el-dialog> 

     <el-button type="primary" @click="dialogVisible1 = true">查询该部门所有请假申请</el-button>
     <el-dialog :visible.sync="dialogVisible1">
            <p>empId:{{selectRecord}}</p>
             <el-form @submit.native.prevent>
              <el-input v-model="selectRecord"
                placeholder="输入员工编号"
                @keyup.enter.native="getManagers">
              </el-input>
            </el-form>
        <el-table :data="ManagerTableData" height="250"
    border
    style="width: 100%">
    <el-table-column prop="id" label="id" width="180">
    </el-table-column>
    <el-table-column prop="emp_id" label="emp_id" width="180">
    </el-table-column>
    <el-table-column prop="name" label="name" width="180">
    </el-table-column>
    <el-table-column prop="department_id" label="department_id" width="180">
    </el-table-column>
    <el-table-column prop="job_id" label="job_id" width="180">
    </el-table-column>
    <el-table-column prop="reason" label="reason" width="180">
    </el-table-column>
    <el-table-column prop="status" label="status" width="180">
    </el-table-column>
    <el-table-column prop="start_date" label="start_date" width="180">
    </el-table-column>
    <el-table-column prop="end_date" label="end_date" width="180">
    </el-table-column>
    <el-table-column prop="apply_time" label="apply_time" width="180">
    </el-table-column>
    <el-table-column prop="deal_time" label="deal_time" width="180">
    </el-table-column>
      </el-table>
   </el-dialog> 
    <!-- 修改用户的基础工资 -->
    <el-button type="primary" @click="dialogVisible2 = true">修改</el-button>
      <el-dialog :visible.sync="dialogVisible2">
        <el-form @submit.native.prevent :model="changeCForm" label-width="150px" :inline="true">
          <el-form-item label="emp_id" prop="emp_id">
              <el-input v-model="changeCForm.emp_id" placeholder="输入员工编号">
              </el-input>
          </el-form-item>
            <el-form-item label="target_id" prop="target_id">
              <el-input v-model="changeCForm.target_id" placeholder="输入目标员工id">
              </el-input>
            </el-form-item>
          <el-form-item label="newBasicSalary" prop="newBasicSalary">
                <el-input v-model="changeCForm.newBasicSalary" placeholder="输入新基础工资-回车执行-下同" @keyup.enter.native="updateBasicSalary">
                </el-input>
              </el-form-item>
          <el-form-item label="newMonthSalary" prop="newMonthSalary">
                <el-input v-model="changeCForm.newMonthSalary" placeholder="输入新月工资" @keyup.enter.native="updateMonthSalary">
                </el-input>
              </el-form-item>
          <el-form-item label="newArrivalTime" prop="newArrivalTime">
                <el-input v-model="changeCForm.newArrivalTime" placeholder="输入员工到岗时间" @keyup.enter.native="updateArrivalTime">
                </el-input>
              </el-form-item>
           <el-form-item label="newDepartureTime" prop="newDepartureTime">
                <el-input v-model="changeCForm.newDepartureTime" placeholder="输入员工离岗时间" @keyup.enter.native="updateDepartureTime">
                </el-input>
          </el-form-item>
          <el-form-item label="newRestDay" prop="newRestDay">
                <el-input v-model="changeCForm.newRestDay" placeholder="输入新的员工职位"  @keyup.enter.native="updatRestDay">
                </el-input>
        </el-form-item>
        <!-- <el-form-item style="width:100%;">
          <el-button type="primary" style="width:100%;" @click="submitForm('addUserForm')">添加</el-button>
        </el-form-item> -->
        </el-form>
      </el-dialog>
  </div>
</template>


<script>
import { clockInEmp,clockOutEmp } from '../../api/userMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      dialogVisible: false,
      dialogVisible1: false,
      dialogVisible2: false,
       title: '添加',
      inputEmpId: '',
      selectRecord: '',
      //放入员工信息
      tableData: [],
      recordTableData: [],
      ManagerTableData: [],
      //输入的上下班打卡员工编号
      clockInEmpId: '',
      clockOutEmpId: '',
      editForm: {
        deptId: '',
        deptName: '',
        deptNo: '',
        token: localStorage.getItem('logintoken')
      },
      
      formInline: {
        page: 1,
        limit: 100,
        varLable: '',
        varName: '',
        token: localStorage.getItem('logintoken')
      },
       changeCForm : {
          emp_id: '',
          target_id: '',
          newBasicSalary: '',
          newMonthSalary: '',
          newArrivalTime: '',
          newDepartureTime: '',
          newRestDay: '',
          newRestDay: ''
          //剩下方法
      },
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },
  

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    getEmployeesByEmpId()  {
      const self = this
      this.$axios.get('/higher/queryAllEmployees?emp_id=' + this.inputEmpId).then((res) => {
        console.log(res)
        self.recordData = res.data
      // eslint-disable-next-line handle-callback-err
      }).catch((error) => {
        alert('false2')
      })
    },

    clockIn() {
      const self = this
      this.$axios.post('/higher/queryRecord?emp_id' + this.clockInEmpId).then((res) => {
        console.log(res)
      }).catch((error) => {
        alert('false2')
      })
    },

    clockOut() {
     const self = this
      this.$axios.post('/higer/queryManagers?emp_id=' + this.clockOutEmpId).then((res) => {
        console.log(res)
      }).catch((error) => {
        alert('false2')
      })
    },

    getstatus()  {
      const self = this
      this.$axios.get('/higher/queryRecord?emp_id=' + this.selectRecord).then((res) => {
        console.log(res)
        self.recordTableData = res.data
      // eslint-disable-next-line handle-callback-err
      }).catch((error) => {
        alert('false2')
      })
    },
     getManagers()  {
      const self = this
      this.$axios.get('/higher/queryManagers?emp_id=' + this.selectRecord).then((res) => {
        console.log(res)
        self.ManagerTableData = res.data
      // eslint-disable-next-line handle-callback-err
      }).catch((error) => {
        alert('false2')
      })
    },

    // getRecordByEmpId() {
    //   // const self = this
    //   this.$axios.get('/higer/queryManagers?emp_id=' + this.selectRecord).then((res) => {
    //     console.log(res)
    //     this.recordTableData = res.data
    //   // eslint-disable-next-line handle-callback-err
    //   }).catch((error) => {
    //     alert('false3')
    //   })
    // }, 
    // 获取公司列表
    getdata(parameter) {
      this.loading = true
      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      deptList(parameter)
        .then(res => {
          this.loading = false
          if (res.success == false) {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            this.listData = res.data
            // 分页赋值
            this.pageparm.currentPage = this.formInline.page
            this.pageparm.pageSize = this.formInline.limit
            this.pageparm.total = res.count
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },

     updateBasicSalary(){
     if(this.changeCForm.emp_id==''){
            alert("emp_id不能为空")
        }else if(this.changeCForm.target_id==''){
            alert("target_id不能为空")}else if(this.changeCForm.newBasicSalary==''){
            alert("newBasicSalary不能为空")
        }else{
          this.$axios.put('/higher/changeMonthly_Salary?emp_id=' + this.changeCForm.emp_id + '&target_id=' +
       this.changeCForm.target_id+'&newValue=' + this.changeCForm.newBasicSalary).then((res) => {
        alert('基础工资更新成功')
        console.log(res)
      // eslint-disable-next-line handle-callback-err
      }).catch((error) => {
        alert('false4')
      })
      }
   },
    updateMonthSalary(){
    if(this.changeCForm.emp_id==''){
            alert("emp_id不能为空")
        }else if(this.changeCForm.target_id==''){
            alert("target_id不能为空")}else if(this.changeCForm.newMonthSalary==''){
            alert("newMonthSalary不能为空")
        }else{
          this.$axios.put('/higher/changeMonthly_Salary?emp_id=' + this.changeCForm.emp_id + '&target_id=' +
       this.changeCForm.target_id+'&newValue=' + this.changeCForm.newMonthSalary).then((res) => {
        alert('基础月薪更新成功')
        console.log(res)
      // eslint-disable-next-line handle-callback-err
      }).catch((error) => {
        alert('false4')
      })
      }
   },
    updateArrivalTime(){
    if(this.changeCForm.emp_id==''){
            alert("emp_id不能为空")
        }else if(this.changeCForm.target_id==''){
            alert("target_id不能为空")}else if(this.changeCForm.newArrivalTime==''){
            alert("newMonthSalary不能为空")
        }else{
          this.$axios.put('/higher/changeArrival_time?emp_id=' + this.changeCForm.emp_id + '&target_id=' +
       this.changeCForm.target_id+'&newValue=' + this.changeCForm.newArrivalTime).then((res) => {
        alert('到岗时间更新成功')
        console.log(res)
      // eslint-disable-next-line handle-callback-err
      }).catch((error) => {
        alert('false4')
      })
      }
   },
   
    updateDepartureTime(){
    if(this.changeCForm.emp_id==''){
            alert("emp_id不能为空")
        }else if(this.changeCForm.target_id==''){
            alert("target_id不能为空")}else if(this.changeCForm.newDepartureTime==''){
            alert("newMonthSalary不能为空")
        }else{
          this.$axios.put('/higher/changeArrival_time?emp_id=' + this.changeCForm.emp_id + '&target_id=' +
       this.changeCForm.target_id+'&newValue=' + this.changeCForm.newDepartureTime).then((res) => {
        alert('离岗时间更新成功')
        console.log(res)
      // eslint-disable-next-line handle-callback-err
      }).catch((error) => {
        alert('false4')
      })
      }
   },
    updatRestDay(){
    if(this.changeCForm.emp_id==''){
            alert("emp_id不能为空")
        }else if(this.changeCForm.target_id==''){
            alert("target_id不能为空")}else if(this.changeCForm.newRestDay==''){
            alert("newMonthSalary不能为空")
        }else{
          this.$axios.put('/higher/changeRestholiday?emp_id=' + this.changeCForm.emp_id + '&target_id=' +
       this.changeCForm.target_id+'&newValue=' + this.changeCForm.newRestDay).then((res) => {
        alert('剩余假期更新成功')
        console.log(res)
      // eslint-disable-next-line handle-callback-err
      }).catch((error) => {
        alert('false4')
      })
      }
   },

  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 